/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.acme.business;

import com.acme.model.Stock;
import com.acme.persistence.StockDao;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author General
 */
public class StockBusinessImpl implements StockBusiness {
    @Autowired
    private StockDao stockDao;
    
    @Transactional
    @Override
    public void createStock(String symbol, String name, String sumary) {
        // validaciones de negocio
        Stock stock = new Stock(symbol, name, sumary);
        stockDao.create(stock);
    }
    
    @Transactional
    @Override
    public void deleteStock(long stock_id) {
        // validaciones
        Stock stock = new Stock();
        stock.setStock_id(stock_id);
        stockDao.delete(stock);
    }
    
    @Transactional
    @Override
    public void updateStock(long stock_id, String symbol, String name, String sumary) {
        // validaciones de negocio
        Stock stock = new Stock(symbol, name, sumary);
        stock.setStock_id(stock_id);
        stockDao.update(stock);
    }
    
    @Transactional
    @Override
    public Stock getStock(long stock_id) {
        return stockDao.findById(stock_id);
    }
    
    @Transactional
    @Override
    public List<Stock> getAllStocks() {
        return stockDao.findAll();
    }

    @Transactional
    @Override
    public void setStockDao(StockDao stockDao) {
        this.stockDao = stockDao;
    }
    
    @Transactional
    @Override
    public List<Stock> findBySymbol(String symbol) {
        System.out.println("symbol: " + symbol);
        return stockDao.findBySymbol(symbol);
    }
}
